<template>
  <van-cell class="comment-item" >
    <van-image
      class="avatar"
      slot='icon'
      round
      :src="comment.aut_photo"
    />
    <div slot="title">
      <div class="title-wrap">
        <div class="name">{{ comment.aut_name }}</div>
        <div class="like-wrap">
          <van-icon
          :name="comment.is_liking? 'good-job': 'good-job-o'"
          class="like-icon" :class="{'liked': comment.is_liking}" @click="handleCommentClick()"></van-icon>
          <span class="like-count">{{ !comment.like_count? '':comment.like_count}}</span>
        </div>
      </div>
      <div class="content">{{ comment.content }}</div>
      <div class="pubdate-wrap">
        <span class="pubdate">{{ comment.pubdate | datetime('MM-DD HH:mm')}}</span>
        <van-button round size="mini" class="reply-btn" @click="$emit('reply-click', comment)">{{ !comment.reply_count? '':comment.reply_count }} 回复</van-button>
      </div>
    </div>
  </van-cell>
</template>

<script>
import { addCommentLike, deleteCommentLike } from '@/api/comment'
export default {
  name: 'CommentItem',
  components: {},
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
    }
  },
  computed: {},
  watch: {},
  mounted () {},
  methods: {
    // 点赞或者取消点赞评论
    async handleCommentClick () {
      if (!this.comment.is_liking) {
        await addCommentLike(this.comment.com_id.toString())
        this.comment.like_count++
      } else {
        await deleteCommentLike(this.comment.com_id.toString())
        this.comment.like_count--
      }
      this.comment.is_liking = !this.comment.is_liking
    }
  }
}

</script>
<style lang='less' scoped>
.comment-item {
  .avatar {
    width: 36px;
    height: 36px;
    margin-right: 13px;
  }
  .title-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .name {
    font-size: 14px;
    color: #406599;
  }
  .content {
    font-size: 16px;
    color: #222;
  }
  .pubdate-wrap {
    display: flex;
    align-items: center;
  }
  .pubdate {
    font-size: 10px;
    margin-right: 10px;
  }
  .like-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .liked {
    color: red;
  }
  .reply-btn{}

}
</style>
